<?php
/* 
* @Author: LDF QQ 47121862
* @Date:   2014-06-03 10:13:58
* @Last Modified by:   LDF QQ 47121862
* @Last Modified time: 2014-06-12 18:02:11
*/
class IndexTag{
	public $tag=array(
		'cate'=>array('block'=>1,'level'=>3),
		'hotCate'=>array('block'=>1,'level'=>3),
		'hotArticle'=>array('block'=>1,'level'=>3),
		'comment'=>array('block'=>1,'level'=>3),
		'xilie'=>array('block'=>1,'level'=>3),
		'link'=>array('block'=>1,'level'=>3),
	);
	//栏目
	function _cate($attr,$content){
		$cid=$attr['cid'];
		$nav = isset($_GET['nav'])?$_GET['nav']:0;
		$row=$attr['row'];
		$php=<<<str
		<?php
		\$re = M('category')->limit($row)->where('pid=0')->all();
		foreach (\$re as \$c) :
			if($nav==\$c['cid']) \$c['act']='act="1"';
			\$c['url']=U(\$c['url'],array('cid'=>\$c['cid'],'nav'=>\$c['cid']));
		?>
str;
		$php.=$content;
		$php.='<?php endforeach ;?>';
		return $php;
	}
	// 热门栏目
	function _hotCate($attr,$content){
		$row=$attr['row'];
		$hits=$attr['hits'];
		$php=<<<str
		<?php
		\$re = M('category')->limit($row)->where('hits>$hits')->all();
		foreach (\$re as \$c) :
			\$c['url']=U('List/index',array('cid'=>\$c['cid'],'nav'=>13));
		?>
str;
		$php.=$content;
		$php.='<?php endforeach ;?>';
		return $php;
	}
	// 热门文章 / 活动等等
	function _hotArticle($attr,$content){
		$row=$attr['row'];
		$cid=isset($attr['cid'])?$attr['cid']:0;
		$php=<<<str
		<?php
		\$re = $cid?M('article')->limit($row)->where('cid=$cid')->order('aid DESC')->all():M('article')->limit($row)->order('aid DESC')->all();
		foreach (\$re as \$a) :
			\$a['urls']=U('Index/content',array('cid'=>\$a['cid'],'aid'=>\$a['aid'],'nav'=>\$a['cid']));
		?>
str;
		$php.=$content;
		$php.='<?php endforeach ;?>';
		return $php;
	}

	// 热门评论
	function _comment($attr,$content){
		$row=$attr['row'];
		$php=<<<str
		<?php
		\$sql = "SELECT a.aid,a.title,a.cid,c.content,c.addtime,u.nickname FROM ldf_comment as c JOIN ldf_article as a ON c.aid=a.aid JOIN ldf_user AS u ON c.uid=u.uid WHERE c.wonderful=1 ORDER BY c.cid DESC LIMIT {$row}";
		\$re = M()->query(\$sql);
		foreach (\$re as \$com) :
			\$com['urls']=U('Index/content',array('cid'=>\$com['cid'],'aid'=>\$com['aid']));
		?>
str;
		$php.=$content;
		$php.='<?php endforeach ;?>';
		return $php;
	}

	// 更多系列
	function _xilie($attr,$content){
		$row=$attr['row'];
		$php=<<<str
		<?php
		\$i=0;
		\$re = M('xilie')->limit($row)->order('xid DESC')->all();
		foreach (\$re as \$x) :
			\$i++;
			\$mod = (\$i%2)?20:0;
			\$x['urls']=U('Xilie/content',array('cid'=>\$_GET['cid'],'xid'=>\$x['xid']));
			\$x['mod']=\$mod;
		?>
str;
		$php.=$content;
		$php.='<?php endforeach ;?>';
		return $php;
	}

	// 友情链接
	function _link($attr,$content){
		$row=$attr['row'];
		$php=<<<str
		<?php
		\$re = M('link')->limit($row)->order('lid DESC')->all();
		foreach (\$re as \$l) :
		?>
str;
		$php.=$content;
		$php.='<?php endforeach ;?>';
		return $php;
	}
}
